package com.vavr.checkincms.controller;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import com.vavr.checkincms.common.domain.BaseResult;
import com.vavr.checkincms.common.domain.ResultEnum;
import com.vavr.checkincms.common.exception.BaseException;
import com.vavr.checkincms.domain.bo.CheckinBO;
import com.vavr.checkincms.service.CheckinService;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RestController;
import java.io.IOException;

/**
 * 签到
 *
 * @since 2024.08
 */
@RestController
public class CheckinController {
    /**
     * checkinService
     */
    private final CheckinService checkinService;

    public CheckinController(CheckinService checkinService) {
        this.checkinService = checkinService;
    }

    /**
     * 签到V1版本
     *
     * @param bo {@link CheckinBO}
     * @param request {@link HttpServletRequest}
     * @param response {@link HttpServletResponse}
     * @return BaseResult<UserDTO>
     */
    @PostMapping("/operation/checkin/v1")
    public BaseResult<String> checkin(@Validated @RequestBody CheckinBO bo, HttpServletRequest request,
            HttpServletResponse response) {
        checkinService.checkin(bo, request, response);
        return BaseResult.of(ResultEnum.OK, ResultEnum.OK.getMsg());
    }

    /**
     * 纯粹的ai跳转
     *
     * @param bo {@link CheckinBO}
     * @param request {@link HttpServletRequest}
     * @param response {@link HttpServletResponse}
     * @return BaseResult<UserDTO>
     */
    @PostMapping("/operation/toChat")
    public BaseResult<String> toChat(@Validated @RequestBody CheckinBO bo, HttpServletRequest request,
            HttpServletResponse response) {
        String chat = null;
        try {
            chat = checkinService.toChat(bo, request, response);
        }
        catch (IOException e) {
            throw new BaseException(ResultEnum.LOGIN_CHAT_AI_ERROR);
        }
        return BaseResult.of(ResultEnum.OK,chat );
    }
}
